package accounting.controller;

import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONArray;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import accounting.assets.model.service.AssetsService;
import accounting.assets.model.vo.AssetsVO;

public class AssetsController extends MultiActionController {
	private AssetsService assetsService;

	public void setAssetsServiceImpl(AssetsService assetsService) {
		this.assetsService = assetsService;
	}
	
	public ModelAndView goAssets(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
	
		return new ModelAndView("assets_result.tiles");
	}
	
	public ModelAndView selectTotalAssets(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		List<AssetsVO> voList = (List) assetsService.selectTotalAssets();
		JSONArray list=new JSONArray(voList);
		PrintWriter out=response.getWriter();
		out.print(list);
		out.close();
		return new ModelAndView("assets_result.tiles");
	}

	public ModelAndView insertAssets(HttpServletRequest request,
			HttpServletResponse response, AssetsVO vo) throws Exception {
		// request.setAttribute("test", "test111");
		System.out.println(vo);
		assetsService.insertAssets(vo);
		List voList = (List) assetsService.selectTotalAssets();
		JSONArray list=new JSONArray(voList);
		return new ModelAndView("insert_assets_result.tiles","list",list);
	}
}
